package com.juhuixing.common.utils.date;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

/**
 * @ClassName ConstellationUtil
 * @Description 根据日期计算星座
 * @Author 刘猛
 * @Date 2019/6/25 13:35
 **/
public class ConstellationUtil {

    /**
     * 星座枚举
     **/
    enum ConstellationEnum {
        aries(321,419,"白羊座"),
        taurus(420,520,"金牛座"),
        gemini(521,621,"双子座"),
        cancer(622,722,"巨蟹座"),
        leo(723,822,"狮子座"),
        virgo(823,922,"处女座"),
        libra(923,1023,"天秤座"),
        scorpio(1024,1122,"天蝎座"),
        sagittarius(1123,1221,"射手座"),
        aquarius(120,218,"水瓶座"),
        pisces(219,320,"双鱼座"),
        capricorn(null,null,"摩羯座");

        private Integer start;
        private Integer end;
        private String name;

        ConstellationEnum(final Integer start,final Integer end, final String name) {
            this.start = start;
            this.end = end;
            this.name = name;
        }

        public Integer getStart() {
            return this.start;
        }
        public Integer getEnd() {
            return this.end;
        }
        public String getName() {
            return this.name;
        }


    }

    /**
     * 功能描述: 获取星座
     * @methodName getConstellation
     * @author: 刘猛
     * @date: 2019/6/25 13:42
     * @param: [birthDay]
     * @return: java.lang.String
     **/
    public static String getConstellation(String birthDay){
        DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        LocalDate ld = LocalDate.parse(birthDay,df);
        int month = ld.getMonthValue();
        int day = ld.getDayOfMonth();
        int key = Integer.valueOf(month+""+ (String.valueOf(day).length() == 1 ? ("0"+day) : day));
        String result;
        if(key >= ConstellationEnum.aries.getStart() && key <= ConstellationEnum.aries.getEnd()){
            result = ConstellationEnum.aries.getName();
        }else if(key >= ConstellationEnum.taurus.getStart() && key <= ConstellationEnum.taurus.getEnd()){
            result = ConstellationEnum.taurus.getName();
        }else if(key >= ConstellationEnum.gemini.getStart() && key <= ConstellationEnum.gemini.getEnd()){
            result = ConstellationEnum.gemini.getName();
        }else if(key >= ConstellationEnum.cancer.getStart() && key <= ConstellationEnum.cancer.getEnd()){
            result = ConstellationEnum.cancer.getName();
        }else if(key >= ConstellationEnum.leo.getStart() && key <= ConstellationEnum.leo.getEnd()){
            result = ConstellationEnum.leo.getName();
        }else if(key >= ConstellationEnum.virgo.getStart() && key <= ConstellationEnum.virgo.getEnd()){
            result = ConstellationEnum.virgo.getName();
        }else if(key >= ConstellationEnum.libra.getStart() && key <= ConstellationEnum.libra.getEnd()){
            result = ConstellationEnum.libra.getName();
        }else if(key >= ConstellationEnum.scorpio.getStart() && key <= ConstellationEnum.scorpio.getEnd()){
            result = ConstellationEnum.scorpio.getName();
        }else if(key >= ConstellationEnum.sagittarius.getStart() && key <= ConstellationEnum.sagittarius.getEnd()){
            result = ConstellationEnum.sagittarius.getName();
        }else if(key >= ConstellationEnum.aquarius.getStart() && key <= ConstellationEnum.aquarius.getEnd()){
            result = ConstellationEnum.aquarius.getName();
        }else if(key >= ConstellationEnum.pisces.getStart() && key <= ConstellationEnum.pisces.getEnd()){
            result = ConstellationEnum.pisces.getName();
        }else{
            result = ConstellationEnum.capricorn.getName();
        }
        return result;
    }
}
